/* spu模块接口 */
import httpInstance from '@/utils/http'
/* 数据类型约束 */
import type {
  resSpuData,
  resAllMark,
  resAllSalesAttr,
  resSpuImage,
  resSales,
  skuSee,
} from './spuTypes'
/* spu模块所有接口管理地址 */
enum API {
  /* 获取初始spu信息 */
  /* 获取已有的SPU的数据 */
  HASSPU_URL = '/admin/product/',
  /* 获取全部品牌的数据 */
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  /* 获取某个SPU下的全部的售卖商品的图片数据 */
  IMAGE_URL = '/admin/product/spuImageList/',
  /* 获取某一个SPU下全部的已有的销售属性接口地址 */
  SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
  /* 获取整个项目全部的销售属性  [颜色、版本、尺码]*/
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  /* 追加一个新的SPU */
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  /* 更新已有的SPU */
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  /* 追加一个新增的SKU地址 */
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  /* 查看某一个已有的SPU下全部售卖的商品 */
  SKUINFO_URL = '/admin/product/findBySpuId/',
  /* 删除已有的SPU */
  REMOVESPU_URL = '/admin/product/deleteSpu/',
}
/* 获取初始spu信息 */
export const getBaseSpuAPI = ({ page, limit, category3Id }: any) => {
  return httpInstance.get<any, resSpuData>(
    API.HASSPU_URL + `${page}/${limit}?category3Id=${category3Id}`,
  )
}
/* 获取全部SPU商品数据 */
export const getAllSpuAPI = () => {
  return httpInstance.get<any, resAllMark>(API.ALLTRADEMARK_URL)
}
/* 获取某个SPU下的全部的售卖商品的图片数据 */
export const getSpuImageAPI = (id: number) => {
  return httpInstance.get<any, resSpuImage>(API.IMAGE_URL + id)
}
/* 获取某一个SPU下全部的已有的销售属性接口地址 */
export const getSaleAttrAPI = (id: number) => {
  return httpInstance.get<any, resSales>(API.SPUHASSALEATTR_URL + id)
}
/* 获取全部销售属性 */
export const getSaleAttributeAPI = () => {
  return httpInstance.get<any, resAllSalesAttr>(API.ALLSALEATTR_URL)
}
/* 修改SPU 或者 添加SPU */
export const putUpdataSpuApi = (data: any) => {
  /* 有id 就修改 */
  if (data.id) {
    return httpInstance.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    /* 添加 */
    return httpInstance.post<any, any>(API.ADDSPU_URL, data)
  }
}
/* 删除已有的SPU */
export const deletSpuAPI = (id: number | string) => {
  return httpInstance.delete<any, any>(API.REMOVESPU_URL + id)
}
/* 追加一个新增的SKU地址 */
export const reqAddSku = (data: any) => {
  return httpInstance.post<any, any>(API.ADDSKU_URL + data)
}
/* 查看某一个已有的SPU下全部售卖的商品 */
export const reqSeeSku = (id: number | string) => {
  return httpInstance.get<any, skuSee>(API.SKUINFO_URL + id)
}
